package com.xiaoshuidi.cloud.module.system.controller.admin.ocr.config;

import com.aliyun.ocr_api20210707.Client;
import com.aliyun.teaopenapi.models.Config;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;

@Data
@Slf4j
@RefreshScope
@ConfigurationProperties(prefix = "ocr.config")
public class OcrClientConfig {
    private String accessKeyId;
    private String accessKeySecret;

    public Client ocrClient() {
        try {
            Config config = new Config()
                    // 必填，您的 AccessKey ID
                    .setAccessKeyId(accessKeyId)
                    // 必填，您的 AccessKey Secret
                    .setAccessKeySecret(accessKeySecret);
            // 访问的域名
            config.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
            return new Client(config);
        } catch (Exception e) {
            log.error("OCR识别初始化Client失败，异常信息：", e);
        }
        return null;
    }
}
